<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2018-2018 http://www.donglixia.net All rights reserved.
// +----------------------------------------------------------------------
// | Author: 十万马 <962863675@qq.com>
// +----------------------------------------------------------------------
// | DateTime: 2018-02-09 16:17
// +----------------------------------------------------------------------

namespace app\admin_fussen\model;

use app\common\model\Article as CoreArticle;
use think\Db;

class Article extends CoreArticle
{
    /**
     * 获取文章类目下拉列表，带前置符号|----
     * @param array $map
     * @return string
     */
    public function getCatTableTree($map = [])
    {
        $map['state'] = 1;
        $map['language'] = session('config.language');
        $catList = Db::name('article_cat')->where($map)->field('cat_id as value,pid,cat_name as name')->order('sort_num asc, cat_id desc')->select();
        return \Tree::get_Table_tree($catList, 'name', 'value');
    }

    /**
     * 获取文章类目下拉列表HTML<option>
     * @param array $map
     * @param int $value 默认选中id
     * @return string
     */
    public function getCatOptionTree($map = [], $value = 0)
    {
        $map['state'] = 1;
        $map['language'] = session('config.language');
        $catList = Db::name('article_cat')->where($map)->field('cat_id,pid,cat_name')->order('sort_num asc, cat_id desc')->select();
        return \Tree::get_option_tree($catList, $value, 'cat_name', 'cat_id', 'pid');
    }

    /**
     * 获取扩展类目下拉列表HTML<option>（多选）
     * @param array $map
     * @param array $value 默认选中id
     * @return string
     */
    public function getCatExtOptionTree($map = [], $value = [])
    {
        $map['state'] = 1;
        $map['language'] = session('config.language');
        $catList = Db::name('article_cat')->where($map)->field('cat_id,pid,cat_name')->order('sort_num asc, cat_id desc')->select();
        return \Tree::get_multiple_option_tree($catList, $value, 'cat_name', 'cat_id', 'pid');
    }

}